async_mode = None

from flask import Flask, render_template
import socketio

sio = socketio.Server(async_mode=async_mode)
app = Flask(__name__)
app.wsgi_app = socketio.WSGIApp(sio, app.wsgi_app)


@app.route('/')
def index():
    return render_template('latency.html')


@sio.event
def ping_from_client(sid):
    #print(data)
    sio.emit('pong_from_server', room=sid)

@sio.event
def data_from_client(sid, data):
    print(data)
    sio.emit('receipt_from_server', room=sid)


if __name__ == '__main__':
    if sio.async_mode == 'threading':
        # deploy with Werkzeug
        app.run(threaded=True)
    elif sio.async_mode == 'eventlet':
        # deploy with eventlet
        import eventlet
        import eventlet.wsgi
        eventlet.wsgi.server(eventlet.listen(('', 6606)), app)
    else:
        print('Unknown async_mode: ' + sio.async_mode)
